//Start functions of PrimitiveType
var PrimitiveTypeTemplate = "templates/PrimitiveType.xsl"

function loadPrimitiveTypeData(xID){
	if(objectHTTPXML) {
		xIDTmp = xID
		waitBox = new Lightbox.base('box1');
		objectHTTPXML.open('GET', '/model.load.primitivetype?id=' + xID + '&m_id=' + modelID , true)
		objectHTTPXML.onreadystatechange = returnPrimitiveTypeData
		objectHTTPXML.send(null)
	} else {
		alert("Your browser don't suport Ajax")
	}
}

function returnPrimitiveTypeData(){
	if (objectHTTPXML.readyState == 4) {
		xml = objectHTTPXML.responseXML
		template = loadXSLfromXML(PrimitiveTypeTemplate, xml)
		document.getElementById("divBody").innerHTML = template
		waitBox.hideBox(null);
	}			
}

function savePrimitiveType(xID){
	if(objectHTTPXML) {
		var parameters = "m_id=" + modelID +
						 "&id=" + encodeURI(document.getElementById("id").value) +
						 "&name=" + encodeURI(document.getElementById("name").value)
						 						 
		xIDTmp = xID
		
		waitBox = new Lightbox.base('box1');

		objectHTTPXML.onreadystatechange = returnSavePrimitiveType
		objectHTTPXML.open('POST', '/model.save.primitivetype', true);
		objectHTTPXML.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		objectHTTPXML.setRequestHeader("Content-length", parameters.length);
		objectHTTPXML.setRequestHeader("Connection", "close");
		objectHTTPXML.send(parameters);
	} else {
		alert("Your browser don't suport Ajax")
	}
}

function returnSavePrimitiveType(){
	if (objectHTTPXML.readyState == 4) {
		waitBox.hideBox(null);
		if(objectHTTPXML.responseText == 'OK'){
			changeName(xIDTmp, document.getElementById("name").value)
			alert('Data saved!')
		} else {
			alert('Data not saved!')
			loadPrimitiveTypeData(xIDTmp)
		}
	}			
}

function createPrimitiveType(xID){
	if(objectHTTPXML) {
		xIDTmp = xID
		waitBox = new Lightbox.base('box1');
		objectHTTPXML.open('GET', '/model.create.primitivetype?&m_id=' + modelID + '&p_id=' + xID , true)
		objectHTTPXML.onreadystatechange = returnPrimitiveType
		objectHTTPXML.send(null)
	} else {
		alert("Your browser don't suport Ajax")
	}
}

function returnPrimitiveType(){
	if (objectHTTPXML.readyState == 4) {
		if(objectHTTPXML.responseText.split("$$$$").length != 0){
			id = objectHTTPXML.responseText.split("$$$$")
			createNewNode(xIDTmp, id[0], id[1], 'javascript:loadPrimitiveTypeData("' + id[0] + '");', 'ptype.gif', 'ptype.gif')
		} else {
			alert('Error to create the primite type!')
		}
		waitBox.hideBox(null);
	}			
}

//End functions of PrimitiveType